home *** CD-ROM | disk | FTP | other *** search
- Path: news.iadfw.net!usenet
- From: alpet@airmail.net (Adam Peterson)
- Newsgroups: comp.lang.c
- Subject: Re: Help-Assignment2// This time I am posting the code!!!Thanx
- Date: Sat, 24 Feb 1996 09:02:39 GMT
- Organization: customer of Internet America
- Message-ID: <4gmdb3$c3p@news-f.iadfw.net>
- References: <312e8912.8777775@news.planet.net>
- NNTP-Posting-Host: dal19-06.ppp.iadfw.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- >The program below runs and does the specifed tasks but is not in
- >function prototype form. Any Idea's on passing the array values to
- >these functions????
-
- Code below run on pc with MSC...
- Adam
-
- Note 2 different styles of pointer use in the three functions...
-
-
- #include<stdio.h>
-
-
- void CalcMax(float *fArray, int amount);
- void CalcMin(float *fArray, int amount);
- void CalcAvg(float *fArray, int amount);
-
-
- void CalcMax(float *fArray, int amount)
- {
- float max;
- float *fTemp;
- int i;
- /* max value calculation*/
- fTemp = fArray;
- max = *fTemp;
-
- for (i = 1; i < amount;i++) // arrays start at zero in c
- {
- if (*fTemp>max)
- max=*fTemp;
- fTemp++;
- }
-
-
- printf("\n\nThe Max Value of all entered is: %5.1f\n",max);
-
- }
-
- void CalcMin(float *fArray, int amount)
- {
- float min;
- int i;
-
- min=*fArray; /* min value
- calculation */
-
- for (i = 1; i <amount; i++)
- if (*(fArray + i) < min)
- min=*(fArray + i);
-
- printf("\n\nThe Min Value of all entered is: %5.1f\n",min);
-
- }
-
-
- void CalcAvg(float *fArray, int amount)
- {
-
- float avg;
- int i;
-
- /* average value calculation */
-
- for (i = 0; i < amount; i++)
- avg += *(fArray + i);
-
- printf("\n\nThe Avg Value of all entered is: %6.2f\n",avg/amount);
-
- }
-
-
-
- main()
- {
-
- float A[100];
- int amount;
- int i; // have a problem using 'total' as an incrementing
- counter
- // plus, a counter for an array shouldn't be float
-
-
- printf(" This Program accepts values from the user up to\n"
- " a maximum 100 and calculates the high, low and \n"
- " average of the total values entered.\n");
-
- printf("\nPlease enter the amount of values you wish to use ?\n\n");
- scanf("%i",&amount);
-
- for ( i = 0; i <= amount-1; i++)
-
- { printf(" \nPlease enter a number : ");
- scanf("%f",&A[i]);}
-
-
- printf(" \n\nThe values you have entered are as follows\n\n");
-
- for (i = 0; i < amount; i++)
-
- printf("%6.1f",A[i]);
-
- CalcMax(A, amount);
- CalcMin(A, amount);
- CalcAvg(A, amount);
-
-
- return 0;
- }
-
-